import moment from 'moment/moment';

const option = {
  height: 'calc(100vh - 440px)',
  calcHeight: 30,
  tip: false,
  searchShow: true,
  searchMenuSpan: 6,
  border: true,
  index: true,
  indexLabel: '序号',
  viewBtn: true,
  selection: true,
  dialogClickModal: false,
  columnBtn: false,
  column: [
    {
      label: '附件类型',
      prop: 'attachType',
      dicUrl: '/api/blade-system/dict/dictionary?code=attach_type',
      props: {
        label: 'dictValue',
        value: 'dictKey'
      },
      clearable: false,
      searchSpan: 4,
      search: true,
      type: 'select'
    },
    {
      label: '附件原名',
      prop: 'originalName',
      search: true,

      searchSpan: 4
    },
    {
      label: '附件大小',
      prop: 'attachSize',
      slot: true
    },
    {
      label: '上传时间',
      prop: 'createTime'
    },
    {
      label: '上传人员',
      prop: 'createName',
      search: true,
      searchSpan: 4
    }
  ]
};

//不同表格的option
const getTableOption = (type, safe) => {
  const columMap = {
    esop: [
      {
        label: '附件类型',
        prop: 'attachType',
        dicUrl: '/api/blade-system/dict/dictionary?code=attach_type',
        props: {
          label: 'dictValue',
          value: 'dictKey'
        },
        clearable: false,
        searchSpan: 4,
        search: true,
        type: 'select'
      },
      {
        label: '附件原名',
        prop: 'originalName',
        search: true,
        searchSpan: 4
      },
      {
        label: '附件大小',
        prop: 'attachSize',
        slot: true
      },
      {
        label: '上传时间',
        prop: 'createTime'
      },
      {
        label: '上传人员',
        prop: 'createName',
        search: true,
        searchSpan: 4
      }
    ],
    qms: [
      {
        label: '附件类型',
        prop: 'attachType',
        dicUrl: '/api/blade-system/dict/dictionary?code=ATTACH_QMS_FILE',
        value: 'QMS',
        props: {
          label: 'dictValue',
          value: 'dictKey'
        },
        clearable: false,
        searchSpan: 4,
        searchOrder: 1,
        search: true,
        type: 'select'
      },
      {
        label: '品质类型',
        prop: 'attachSubType',
        dicUrl: '/api/blade-system/dict/dictionary?code=ATTACH_SUB_TYPE',
        props: {
          label: 'dictValue',
          value: 'dictKey'
        },
        searchSpan: 4,
        search: true,
        type: 'select',
        searchOrder: 5
      },
      {
        label: '附件原名',
        prop: 'originalName',
        search: true,
        searchSpan: 4,
        searchOrder: 4
      },
      {
        label: '附件大小',
        prop: 'attachSize',
        slot: true
      },
      {
        label: '上传时间',
        prop: 'createTime'
      },
      {
        label: '上传人员',
        prop: 'createName',
        search: true,
        searchSpan: 4
      }
    ],
    other: [
      {
        label: '附件类型',
        prop: 'attachType',
        dicUrl: '/api/blade-system/dict/dictionary?code=ATTACH_OTHER_FILE',
        props: {
          label: 'dictValue',
          value: 'dictKey'
        },
        searchSpan: 4,
        search: true,
        type: 'select'
      },
      {
        label: '附件地址',
        prop: 'link'
      },
      {
        label: '附件域名',
        prop: 'domain',
        searchSpan: 4
      },
      {
        label: '附件名称',
        prop: 'name',
        searchSpan: 4,
        rules: [
          {
            required: true,
            message: '请输入附件名称',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '附件原名',
        prop: 'originalName',
        search: true,
        searchSpan: 4
      },
      {
        label: '附件拓展名',
        prop: 'extension'
      },
      {
        label: '附件大小',
        prop: 'attachSize',
        slot: true
      },
      {
        label: '上传时间',
        prop: 'createTime'
      },
      {
        label: '上传人员',
        prop: 'createName',
        search: true,
        searchSpan: 4
      }
    ],
    app: [
      {
        label: '附件类型',
        prop: 'attachType',
        dicUrl: '/api/blade-system/dict/dictionary?code=ATTACH_APP_FILE',
        props: {
          label: 'dictValue',
          value: 'dictKey'
        },
        clearable: false,
        searchSpan: 4,
        searchOrder: 1,
        search: true,
        type: 'select'
      },
      {
        label: '品质类型',
        prop: 'attachSubType',
        dicUrl: '/api/blade-system/dict/dictionary?code=ATTACH_SUB_TYPE',
        props: {
          label: 'dictValue',
          value: 'dictKey'
        },
        searchSpan: 4,
        search: true,
        type: 'select',
        searchOrder: 5
      },
      {
        label: '检验单号',
        prop: 'qmsDocumentNo',
        search: true,
        searchSpan: 4
      },
      {
        label: '附件原名',
        prop: 'originalName',
        search: true,
        searchSpan: 4,
        searchOrder: 4
      },
      {
        label: '附件大小',
        prop: 'attachSize',
        slot: true
      },
      {
        label: '上传时间',
        prop: 'createTime'
      },
      {
        label: '上传人员',
        prop: 'createName',
        search: true,
        searchSpan: 4
      }
    ]
  };
  return columMap[type];
};

const attachOption = (safe) => {
  return {
    submitBtn: false,
    emptyBtn: false,
    column: [
      {
        label: '附件类型',
        prop: 'attachType',
        type: 'select',
        value: 'ESOP',
        disabled: true,
        span: 21,
        dicUrl: '/api/blade-system/dict/dictionary?code=ATTACH_ESOP_FILE',
        props: {
          label: 'dictValue',
          value: 'dictKey'
        },
        change: (val) => {
          const column = safe.findObject(safe.attachOption.column, 'attachFile');
          column.data.attachType = val.value;
        },
        rules: [
          {
            required: true,
            message: '请输入附件类型',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '附件上传',
        prop: 'attachFile',
        foemSlot: true
        // type: 'upload',
        // drag: true,
        // loadText: '模板上传中，请稍等',
        // span: 24,
        // propsHttp: {
        //   res: 'data'
        // },
        // data: {
        //   attachType: 'ESOP'
        // },
        // action: '/api/blade-resource/oss/endpoint/exist'
        // action: '/api/blade-resource/oss/endpoint/put-file-attach'
      }
    ]
  };
};

const getAttachOption = (type, safe) => {
  const columMap = {
    esop: [
      {
        label: '附件类型',
        prop: 'attachType',
        type: 'select',
        value: 'ESOP',
        disabled: true,
        span: 21,
        dicUrl: '/api/blade-system/dict/dictionary?code=ATTACH_ESOP_FILE',
        props: {
          label: 'dictValue',
          value: 'dictKey'
        },
        change: (val) => {
          const column = safe.findObject(safe.attachOption.column, 'attachFile');
          column.data.attachType = val.value;
        },
        rules: [
          {
            required: true,
            message: '请输入附件类型',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '附件上传',
        prop: 'attachFile',
        type: 'upload',
        drag: true,
        loadText: '模板上传中，请稍等',
        span: 24,
        propsHttp: {
          res: 'data'
        },
        data: {
          attachType: ''
        },
        action: '/api/blade-resource/oss/endpoint/put-file-attach'
      }
    ],
    qms: [
      {
        label: '附件类型',
        prop: 'attachType',
        type: 'select',
        disabled: true,
        value: 'QMS',
        dicUrl: '/api/blade-system/dict/dictionary?code=ATTACH_QMS_FILE',
        props: {
          label: 'dictValue',
          value: 'dictKey'
        },
        change: (val) => {
          const column = safe.findObject(safe.attachOption.column, 'attachFile');
          column.data.attachType = val.value;
        },
        rules: [
          {
            required: true,
            message: '请输入附件类型',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '品质类型',
        prop: 'attachSubType',
        dicUrl: '/api/blade-system/dict/dictionary?code=ATTACH_SUB_TYPE',
        props: {
          label: 'dictValue',
          value: 'dictKey'
        },
        type: 'select',
        change: (val) => {
          const column = safe.findObject(safe.attachOption.column, 'attachFile');
          column.data.attachSubType = val.value;
          console.log(column, 233333, val);
        },
        rules: [
          {
            required: true,
            message: '请选择品质类型',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '附件上传',
        prop: 'attachFile',
        type: 'upload',
        drag: true,
        loadText: '模板上传中，请稍等',
        span: 24,
        propsHttp: {
          res: 'data'
        },
        data: {
          attachType: '',
          attachSubType: ''
        },
        action: '/api/blade-resource/oss/endpoint/put-file-attach'
      }
    ],
    other: [
      {
        label: '附件类型',
        prop: 'attachType',
        type: 'select',
        span: 21,
        dicUrl: '/api/blade-system/dict/dictionary?code=ATTACH_OTHER_FILE',
        props: {
          label: 'dictValue',
          value: 'dictKey'
        },
        change: (val) => {
          const column = safe.findObject(safe.attachOption.column, 'attachFile');
          column.data.attachType = val.value;
        },
        rules: [
          {
            required: true,
            message: '请输入附件类型',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '附件上传',
        prop: 'attachFile',
        type: 'upload',
        drag: true,
        loadText: '模板上传中，请稍等',
        span: 24,
        propsHttp: {
          res: 'data'
        },
        data: {
          attachType: ''
        },
        action: '/api/blade-resource/oss/endpoint/put-file-attach'
      }
    ],
    app: []
  };
  return columMap[type];
};

export { option, getTableOption, attachOption, getAttachOption };
